package routes

import (
	"simple-crm/config"
	"simple-crm/middleware"
	"simple-crm/services"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

// SetupRoutes 设置所有路由
func SetupRoutes(r *gin.Engine, db *gorm.DB, cfg *config.Config) {
	// 添加全局中间件

	r.Use(middleware.LoggerMiddleware(db))

	// 创建权限服务和中间件（页面路由需要）
	permissionService := services.NewPermissionService(db)
	permissionMiddleware := middleware.NewPermissionMiddleware(permissionService)

	// 设置API路由
	SetupAPIRoutes(r, db, cfg)

	// 设置页面路由
	SetupPageRoutes(r, db, cfg, permissionMiddleware)
}
